package demo.json;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Date;

/**
 * 企微时间反序列化
 *
 * @author sun.ye
 * @since 2020-06-24 15:49
 */
public class QwDateSerializer implements ObjectDeserializer {

    @Override
    public <T> T deserialze(DefaultJSONParser jsonParser, Type type, Object o) {
        String input = jsonParser.getInput();
        JSONObject object = JSON.parseObject(input);
        Long dataL = object.getLong((String) o);
        return (T) new Date(dataL * 1000);
    }

    @Override
    public int getFastMatchToken() {
        return 0;
    }
}